package com.wzy.es.repository;

import com.wzy.es.entity.Movie;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

//@Repository
public interface MoviesRepository extends ElasticsearchRepository<Movie, String> {
//    Page<Movie> findByGenre(String genre, Pageable pageable);

    Page<Movie> findByTitle(String title, Pageable pageable);

    Page<Movie> findByTitleAndGenre(String title, String genre, Pageable pageable);

    Page<Movie> findByTitleAndYearBetween(String title, long begin, long end, Pageable pageable);

    @Query("{    \"bool\": {\n" +
            "      \"must\": [\n" +
            "        {\n" +
            "          \"query_string\": {\n" +
            "            \"query\": \"?0\", \n" +
            "            \"default_operator\": \"OR\"\n" +
            "          }\n" +
            "        },\n" +
            "        {\n" +
            "          \"match\": {\n" +
            "            \"genre\": \"?1\"\n" +
            "          }\n" +
            "        }\n" +
            "      ]\n" +
            "    }}")
    List<Movie> get(String title, String genre);
}
